package com.xhg.xhgone.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/** 全局捕获异常 */
@ControllerAdvice
public class GlobelExceptionHandler {
  @ExceptionHandler(RuntimeException.class) // 运行时异常都可以捕获
  @ResponseBody // 返回json
  public Map<String, Object> exceptionHandler() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("errorCode", 500);
    map.put("errorMsg", "系统错误");
    return map;
  }
}
